home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / demos / winpos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-29  |  1.8 KB  |  103 lines

  1. /* winpos.c */
  2.  
  3. /*
  4.  * Example of how to use the GL_MESA_window_pos extension.
  5.  *
  6.  * Brian Paul
  7.  */
  8.  
  9.  
  10. #include <math.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include "gltk.h"
  15.  
  16.  
  17. #ifndef M_PI
  18. #  define M_PI 3.14159265
  19. #endif
  20.  
  21.  
  22. static TK_RGBImageRec *image;
  23.  
  24.  
  25.  
  26. static void draw( void )
  27. {
  28.    GLfloat angle;
  29.    char *extensions;
  30.  
  31.    extensions = (char *) glGetString( GL_EXTENSIONS );
  32.    if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  33.       printf("Sorry, GL_MESA_window_pos extension not available.\n");
  34.       return;
  35.    }
  36.  
  37.    glClear( GL_COLOR_BUFFER_BIT );
  38.  
  39.    for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  40.       GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  41.       GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  42.  
  43.       /* Don't need to worry about the modelview or projection matrices!!! */
  44. #ifdef GL_MESA_window_pos
  45.       glWindowPos2fMESA( x, y );
  46. #endif
  47.       glDrawPixels( image->sizeX, image->sizeY, GL_RGB,
  48.                     GL_UNSIGNED_BYTE, image->data );
  49.    }
  50. }
  51.  
  52.  
  53.  
  54.  
  55. static GLenum key(int k, GLenum mask)
  56. {
  57.    switch (k) {
  58.       case TK_ESCAPE:
  59.      tkQuit();
  60.    }
  61.    return GL_FALSE;
  62. }
  63.  
  64.  
  65.  
  66. /* new window size or exposure */
  67. static void reshape( int width, int height )
  68. {
  69.    glViewport(0, 0, (GLint)width, (GLint)height);
  70. }
  71.  
  72.  
  73. static void init( void )
  74. {
  75.    char *filename = "../samples/1.rgb";
  76.    image = tkRGBImageLoad( filename );
  77.  
  78.    if (!image) {
  79.       printf("Error: couldn't load image file: %s\n", filename );
  80.       exit(1);
  81.    }
  82. }
  83.  
  84.  
  85. int main( int argc, char *argv[] )
  86. {
  87.    tkInitPosition(0, 0, 500, 500);
  88.    tkInitDisplayMode( TK_RGB | TK_DIRECT );
  89.  
  90.    if (tkInitWindow("winpos") == GL_FALSE) {
  91.       tkQuit();
  92.    }
  93.  
  94.    init();
  95.  
  96.    tkExposeFunc( reshape );
  97.    tkReshapeFunc( reshape );
  98.    tkKeyDownFunc( key );
  99.    tkDisplayFunc( draw );
  100.    tkExec();
  101.    return 0;
  102. }
  103.